package zzz.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import zzz.core.Constants;
import zzz.model.Manager;
import zzz.model.Post;
import zzz.service.ManagerService;

@Controller
@RequestMapping("/manager")
public class ManagerAction extends BaseAction{

	@Autowired()
	private ManagerService managerService;
	
	@RequestMapping("/managerlogin")
	public String managerLogin(HttpSession session,Manager manager,Map<String,String> m){
		Manager ma=managerService.managerLogin(manager);
		String result=null;
		if(ma!=null){
			if(ma.getMgPwd().equals(manager.getMgPwd())){
				session.setAttribute(Constants.LOGIN_MANAGER, ma);
				result="manager/managerIndex";
			}else{
				m.put("msg", "用户密码错误");
				m.put("herf", "../managerindex");
				result="common/msgModal";
			}
		}else{
			m.put("msg", "管理员不存在");
			m.put("herf", "../managerindex");
			result="common/msgModal";
		}
		return result;
	}
	@RequestMapping("/managerloginout")
	public String managerLoginout(){
		getSession().invalidate();
		return "redirect:../managerindex";
	}
}
